/*
 * #%L
 * ServerDAO
 * %%
 * Copyright (C) 2011 Ractoc.com
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ractoc.opengamefinder.dao;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Version;

import org.hibernate.annotations.AccessType;

/**
 * Object representation of a database record in the DOWNLOADABLE_CONTENT table.
 * This is a "container" DAO and should not be use directly. 
 * Instead, this DAO should be extended by the actual content. 
 * An example of this is the AvatarDAO.
 * 
 * @author ractoc
 * @since 0.1
 */
@Entity
@AccessType("property")
@Table(name = "DOWNLOADABLE_CONTENT")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
    name="CONTENT_TYPE",
    discriminatorType=DiscriminatorType.STRING
)
public abstract class DownloadableContentDAO implements Serializable {
    
    private Integer id;
    private Integer version;
    private byte[] content;
    private String type;

    /**
     * Get the type of the downloadable content. 
     * This is the file extension of the original file.
     * @return The filetype.
     */
    public String getType() {
        return type;
    }

    /**
     * Set the type of the downloadable content. 
     * This is the file extension of the original file.
     * @param type The filetype.
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * Set the id of the player account.
     * @param idParam The id of the player account.
     */
    public void setId(final Integer idParam) {
        this.id = idParam;
    }

    /**
     * Get the id of the player account.
     * @return The id of the player account.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CONTENT_ID")
    public Integer getId() {
        return id;
    }
    
    /**
     * Get the version of the record, used for optimistic locking.
     * @return The version of the record.
     */
    @Version
    @Column(name = "VERSION")
    public Integer getVersion() {
        return version;
    }

    /**
     * Set the version of the record, used for optimistic locking.
     * @param versionParam The version of the record.
     */
    public void setVersion(final Integer versionParam) {
        this.version = versionParam;
    }

    /**
     * Get the actual downloadable content in a byte array.
     * @return The actual downloadable content.
     */
    @Lob
    @Basic(fetch= FetchType.LAZY)
    @Column(name = "CONTENT", nullable = false)
    public byte[] getContent() {
        return content;
    }

    /**
     * Set the actual downloadable content in a byte array.
     * @param content The actual downloadable content.
     */
    public void setContent(byte[] content) {
        this.content = content;
    }
}
